package com.me.jingdongshop.ui.activity;

import android.os.Bundle;
import android.os.Message;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;

import com.me.common.base.BaseActivity;
import com.me.jingdongshop.R;
import com.me.jingdongshop.ui.fragment.goods.GoodsDetailDetailFragment;
import com.me.jingdongshop.ui.fragment.goods.GoodsDetailEvaluateFragment;
import com.me.jingdongshop.ui.fragment.goods.GoodsDetailGoodsFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by YL on 2017/5/6.
 */

public class GoodsDetailActivity extends BaseActivity {
    private android.widget.ImageView btnBack;
    private android.support.design.widget.TabLayout productDetailTab;
    private android.widget.ImageView productDetailCart;
    private android.support.v4.view.ViewPager productDetailVp;
    public void setToDetail() {
        if(productDetailVp != null) {
            productDetailVp.setCurrentItem(2);
        }
    }

    @Override
    public int getLayoutRes() {
        return R.layout.product_detail;
    }

    @Override
    public void initView() {

        btnBack = (ImageView) findViewById(R.id.btn_back);
        btnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        productDetailTab = (TabLayout) findViewById(R.id.product_detail_tab);
        productDetailCart = (ImageView) findViewById(R.id.product_detail_cart);
        productDetailVp = (ViewPager) findViewById(R.id.product_detail_vp);

        initViewPager();
    }

    private void initViewPager() {
        final String[] titles = new String[]{
                "商品", "详情", "评价"
        };
        final List<Fragment> fragments = new ArrayList<>();
        int id = getIntent().getIntExtra("id", 1);
        GoodsDetailGoodsFragment goodsFragment = new GoodsDetailGoodsFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("id",id);
        goodsFragment.setArguments(bundle);
        fragments.add(goodsFragment);

        fragments.add(new GoodsDetailDetailFragment());
        fragments.add(new GoodsDetailEvaluateFragment());
        productDetailVp.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }
        });
        productDetailTab.setupWithViewPager(productDetailVp);
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void onClick(View v, int id) {

    }

    @Override
    public void onHttpSuccess(int reqType, Message msg) {

    }

    @Override
    public void onHttpError(int reqType, String error) {

    }
}
